package jp.ekasi.common.emf.util;

import java.util.List;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;

public class EmfUtil {

	/**
	 * 
	 * @param element
	 * @param property
	 * @return
	 */
	public static EAttribute getEAttributeOf(EObject element,String property) {
		EAttribute result = null;		
		List<EAttribute> list = element.eClass().getEAllAttributes();
		for (EAttribute attribute : list) {			
			if(attribute.getName().equals(property)) {
				result = attribute;
			}
		}
		return result;
	}
	
	/**
	 * 
	 * @param element
	 * @param property
	 * @return
	 */
	public static EStructuralFeature getEStructuralFeatureOf(EObject element,String property) {
		EStructuralFeature result = null;		
		List<EStructuralFeature> list = element.eClass().getEAllStructuralFeatures();
		for (EStructuralFeature structuralFeature : list) {			
			if(structuralFeature.getName().equals(property)) {
				result = structuralFeature;
			}
		}
		return result;
	}
	
}
